using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OleDb;
using QuanLyThuVien1.DTO;
namespace QuanLyThuVien1.DAO
{
    public class CPHIEUTRA_DAO
    {
        public DataTable layDSPT()
        {
            DataTable DS = new DataTable();
            OleDbConnection connect = KETNOI.taoKetNoi();
            string connecstr = "select * from PHIEUTRA";
            OleDbDataAdapter oleDb = new OleDbDataAdapter(connecstr, connect);
            oleDb.Fill(DS);
            connect.Close();
            return DS;

        }
        public PHIEUTRA timKiemPT(string maPT)
        {
            PHIEUTRA PT = new PHIEUTRA();
            OleDbConnection connect = KETNOI.taoKetNoi();
            string connecstr = "select * from PHIEUTRA where soPhieuTra = " + maPT;
            OleDbCommand command = new OleDbCommand(connecstr,connect);
            OleDbDataReader Reader = command.ExecuteReader();
            while (Reader.Read())
            {
                PT.SOPHIEUTRA = Reader.GetString(0);
                PT.NGAYTRATHATSU = Reader.GetDateTime(1);
                PT.MAPM = Reader.GetString(2);
            }
            connect.Close();
            Reader.Close();
            return PT;
        }
        public void themPT(PHIEUTRA PT)
        {
            OleDbConnection connect = KETNOI.taoKetNoi();
            string connecstr = "insert into PHIEUTRA  values('" + PT.SOPHIEUTRA + "','" + PT.NGAYTRATHATSU + "','" + PT.MAPM + "')";
            OleDbCommand command = new OleDbCommand(connecstr, connect);
            command.ExecuteNonQuery();
            connect.Close();
        }
        public void XoaPT(string maPhieu)
        {
            OleDbConnection connect = KETNOI.taoKetNoi();
            string connecstr = "delete PHIEUTRA where soPhieuTra = '" + maPhieu+"' ";
            OleDbCommand command = new OleDbCommand(connecstr, connect);
            command.ExecuteNonQuery();
            connect.Close();
        }
        public bool KiemTraPhieuTra(string maPM)
        {

            OleDbConnection connect = KETNOI.taoKetNoi();
            string connecstr = "select * PHIEUTRA where maPM = '"+maPM+"'" ;
            OleDbCommand command = new OleDbCommand(connecstr, connect);
            OleDbDataAdapter a = new OleDbDataAdapter(command);
            DataTable d = new DataTable();
            a.Fill(d);
            connect.Close();
            if (d.Rows.Count > 0)
                return true;
            return false;
        }
    }
}
